var ui = require("./ui");

exports.index = function(req, res) {
	if (req.session.user) {
		var locals = { 
			title: "Web Testing", 
			menu: ui.getMenu(), 
			username: req.session.user
		};
		res.render("index", locals);
	} else {
		var locals = {
			title: "Login page"
		};
		res.render('login', locals);
	}
};

exports.login = function(req, res) {
	if (req.body.login == req.body.passwd) {
		req.session.user = req.body.login;
		res.redirect("/");
	} else {
		var locals = {
			title: "Login page",
			error: true
		};
		res.render('login', locals);
	}
};

exports.testing = function(req, res) {
	if (!req.session.user)
		res.redirect("/");
	else {
		var locals = {
			title: "Web Testing System",
			menu: ui.getTestingMenu(),
			username: req.session.user
		};
		res.render('testing', locals);
	}
};